var combinationSum = function (candidates, target) {
  const ans = [];
  // target 是当前差上面总target的值 combine是当前有机会成为数组的组合，ind当前的下标
  const dfs = (target, combine, idx) => {
    if (idx === candidates.length) {
      return;
    }
    if (target === 0) {
      ans.push(combine);
      return;
    }
    // 每一次循环都对该项进行分支
    //对当前的下标进行递归
    dfs(target, combine, idx + 1);
    // 选择当前数
    if (target - candidates[idx] >= 0) {
      dfs(target - candidates[idx], [...combine, candidates[idx]], idx);
    }
  }
  dfs(target, [], 0);
  return ans;
};
let candidates = [2,3,6,7], target = 7
// ()                ((
// ()( ())           (()  (((
